package com.baizhiedu;

import com.baizhiedu.bean.Customer;
import com.baizhiedu.injection.UserDAO;
import com.baizhiedu.injection.UserDAOImpl;
import com.baizhiedu.injection.UserService;
import com.baizhiedu.injection.UserServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * 功能：
 * 作者：HZj
 * 日期：2025/1/5 19:43
 */
@Configuration
@PropertySource("classpath:/init.properties")
public class AppConfig1 {
    @Value("${id}")
    private Integer id;
    @Value("${name}")
    private String name;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Bean
    public UserDAO userDAO(){
        return new UserDAOImpl();
    }

/*    @Bean
    public UserService userService(UserDAO userDAO){
        UserServiceImpl userService = new UserServiceImpl();
        userService.setUserDAO(userDAO);
        return userService;
    }*/

    @Bean
    public UserService userService(){
        UserServiceImpl userService = new UserServiceImpl();
        userService.setUserDAO(userDAO());
        return userService;
    }

    @Bean
    public Customer customer(){
        Customer customer = new Customer();
        customer.setId(this.getId());
        customer.setName(this.getName());
        return customer;
    }
}
